package com.sakura.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.ServletRequestUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

public class BaseController {
    @Resource
    HttpServletRequest request;

    /**
     * 根据前端传入的current、size获取分页数据
     * @return
     */
    public Page getPage(){
        //使用ServletRequestUtils工具类来处理默认情况（默认情况下不传页数、每页数量，此时应返回第一页数据，每页10个）
        Integer current = ServletRequestUtils.getIntParameter(request,"current",1);
        Integer size = ServletRequestUtils.getIntParameter(request,"size",10);

        return new Page(current,size);
    }
}
